#Include G:\AHK\git-ahk-misc\git-ahk-custom-ctrls\RadioGroup.ahk
#Include DrawQueue.ahk
#Include CtrlPalette.ahk
#Include ToolUIBase.ahk

class RectSubMenu extends BaseToolUI {

  w := 211, h := 32
  s := 3, solid := 0

  __New(x, y, mgr) {
    this.x := x, this.y := y, this.mgr := mgr
    overlay := ShinsOverlayClass(x, y, this.w, this.h, 1, 0, 0)
    this.overlay := overlay

    c := '0x000000', c2 := '0x00AAAA', c3 := '0x255e90', c4 := '0x003131'
    w := 30, h := 30

    group := RadioGroup(Rect(1, 1, w * 2, h))
    _r1 := Radio(Rect(0, 0, w, h), c, c2, c3, 1)
    _r1.OnEvent(Radio.ON_CHECKED, (*) => this.solid := 0)
    _r2 := Radio(Rect(30, 0, w, h), c, c2, c3)
    _r2.OnEvent(Radio.ON_CHECKED, (*) => this.solid := 1)
    group.AddRadios(_r1, _r2)
    this.group := group

    me := MouseEvent(overlay.gui.Hwnd)
    me.RegisterOnCondition(MouseEvent.Events.MOUSE_WHEEL,
      (point, *) => point.ConvertToClient(overlay.gui).InBox(1, 1, 30, 30),
      ChangeSize)
    me.Register(MouseEvent.Events.LBUTTON_UP, OnLU)
    me.Register(MouseEvent.Events.LBUTTON_DOWN, OnLD)

    q := DrawQueue(overlay)
    q.Register(ObjBindMethod(this, 'Refresh'))
    this.q := q
    this.p := Palette(60, 5, me, overlay, q)


    ChangeSize(_, up, *) {
      this.s := Clamp((up ? this.s + 1 : this.s - 1), 1, 10)
      q.Update()
    }

    OnLU(point, *) {
      group.OnLU(point)
      q.Update()
    }

    OnLD(point, *) {
      group.OnLD(point)
      q.Update()
    }

  }

  Show() => (this.overlay.gui.Restore(), this.q.Update())
  Hide() => this.overlay.gui.Hide()

  Move(x, y) => this.overlay.gui.Move(x, y)

  Refresh(overlay) {
    overlay.FillRectangle(0, 0, this.w, this.h, '0xff073d33')
    overlay.DrawRectangle(1, 1, this.w - 1, this.h - 1, '0xff01ffe1')

    this.group.Draw(overlay)
    overlay.DrawLine(61, 0, 61, 32, '0xff01ffe1')
    overlay.FillCircle(16, 16, this.s, this.p.c)
    overlay.FillRectangle(40, 10, 12, 12, this.p.c)
    this.mgr.GetHandlerIns().UpdateParam(this.s, this.p.c + (0xFF << 24), this.solid)
  }
}